﻿/**  
* orderReturn.cs
*
* 功 能： N/A
* 类 名： orderReturn
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/11/26 9:29:15   N/A    初版
*
*  
*┌──────────────────────────────────┐
*│　 　│
*│　版权所有：YKF,LB　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SQLite;

namespace Db.DAL
{
    /// <summary>
    /// 数据访问类:orderReturn
    /// </summary>
    public partial class orderReturn
    {
        public orderReturn()
        { }
        #region  BasicMethod



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.orderReturn model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into orderReturn(");
            strSql.Append("AreaId,OrderValue,OrderId)");
            strSql.Append(" values (");
            strSql.Append("@AreaId,@OrderValue,@OrderId)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@AreaId", DbType.Int32,8),
					new SQLiteParameter("@OrderValue", DbType.Int32,8),
					new SQLiteParameter("@OrderId", DbType.Int32,8)};
            parameters[0].Value = model.AreaId;
            parameters[1].Value = model.OrderValue;
            parameters[2].Value = model.OrderId;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.orderReturn model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update orderReturn set ");
            strSql.Append("AreaId=@AreaId,");
            strSql.Append("OrderValue=@OrderValue,");
            strSql.Append("OrderId=@OrderId");
            strSql.Append(" where ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@AreaId", DbType.Int32,8),
					new SQLiteParameter("@OrderValue", DbType.Int32,8),
					new SQLiteParameter("@OrderId", DbType.Int32,8)};
            parameters[0].Value = model.AreaId;
            parameters[1].Value = model.OrderValue;
            parameters[2].Value = model.OrderId;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Model.orderReturn model)
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from orderReturn ");
            strSql.Append(" where ");
            strSql.Append("AreaId=@AreaId and ");
            strSql.Append("OrderValue=@OrderValue and ");
            strSql.Append("OrderId=@OrderId");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@AreaId", DbType.Int32,8),
					new SQLiteParameter("@OrderValue", DbType.Int32,8),
					new SQLiteParameter("@OrderId", DbType.Int32,8)};
            parameters[0].Value = model.AreaId;
            parameters[1].Value = model.OrderValue;
            parameters[2].Value = model.OrderId;
            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.orderReturn GetModel()
        {
            //该表无主键信息，请自定义主键/条件字段
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AreaId,OrderValue,OrderId from orderReturn ");
            //strSql.Append(" where ");
            SQLiteParameter[] parameters = {
			};

            Model.orderReturn model = new Model.orderReturn();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.orderReturn DataRowToModel(DataRow row)
        {
            Model.orderReturn model = new Model.orderReturn();
            if (row != null)
            {
                if (row["AreaId"] != null && row["AreaId"].ToString() != "")
                {
                    model.AreaId = int.Parse(row["AreaId"].ToString());
                }
                if (row["OrderValue"] != null && row["OrderValue"].ToString() != "")
                {
                    model.OrderValue = int.Parse(row["OrderValue"].ToString());
                }
                if (row["OrderId"] != null && row["OrderId"].ToString() != "")
                {
                    model.OrderId = int.Parse(row["OrderId"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select AreaId,OrderValue,OrderId ");
            strSql.Append(" FROM orderReturn ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.QueryDataSet(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM orderReturn ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQLite.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Id desc");
            }
            strSql.Append(")AS Row, T.*  from orderReturn T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQLite.QueryDataSet(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "orderReturn";
            parameters[1].Value = "Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

